package com.ecar.api.support.util;

import com.ecar.api.support.dto.WsPayload;
import com.ecar.api.websocket.WebSocketManager;
import com.ecar.common.util.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.JedisPubSub;

/**
 * Redis Subscribe事件监听处理类
 * Created by admin on 2016/12/9.
 */
public class SubListener extends JedisPubSub {

	private static final Logger log = LoggerFactory.getLogger(SubListener.class);

	public SubListener() { }

	@Override
	public void onMessage(String channel, String message) {
		log.debug("channel: {}, msg: {}", channel, message);
		WebSocketManager.send(JSONUtil.deserialize(message, WsPayload.class));
	}

	@Override
	public void onSubscribe(String channel, int subscribedChannels) {
		log.info("subscribe channel: {}, count: {}", channel, subscribedChannels);
	}

	@Override
	public void onUnsubscribe(String channel, int subscribedChannels) {
		log.info("unsubscribe channel: {}, count: {}", channel, subscribedChannels);
	}
}
